package com.band.controller;

import com.band.entity.*;
import com.band.exception.ClazzStatuException;
import com.band.mapper.StudentMapper;
import com.band.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;


    /**
     * 条件分页查询
     * @param param
     * @return
     */
    @GetMapping
    public Result list(ClazzQueryParam param){
        log.info("查询参数：{}", param);
        PageBean pageBean = clazzService.list(param);
        return Result.success(pageBean);
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级：{}", id);
        clazzService.delete(id);
        return Result.success();
    }

    /**
     * 新增班级
     * @param clazz
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody Clazz clazz){
        log.info("新增班级：{}", clazz);
        clazzService.insert(clazz);
        return Result.success();
    }

    /**
     * 数据回显
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("查询班级：{}", id);
        Clazz clazz = clazzService.select(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    /**
     * 查询所有班级
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }
}
